﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Com.Toook.Common;
using Com.Toook.DAL;

public partial class UserControls_JokeRecommendControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitRecommend();
    }
    /// <summary>
    /// 随机推荐同类笑话
    /// </summary>
    private void InitRecommend()
    {
        rptRecommend.DataSource = RecommendData.GetRecommend(RecommendType.Joke, RecommendId.Joke, Request["type"], 15, false);
        rptRecommend.DataBind();
        /*
        int type = ParamHelper.ParseIntPositive(Request["type"]);
        
        int total = 1;
        DataRow row = null;
        //类型不为空且是数字，设置类型条件。否则不加类型条件。
        if (type > 0 && type != 50)
        {
            row = PageData.SelectParamRow("typeCode='joke" + type.ToString() + "'");
        }        
        if (row == null)//没有找到，类型不对.设置为默认
        {
            row = PageData.SelectParamRow("typeCode='joke'");
            type = 50;
        }

        int showCount = 15;//随机推荐显示数
        total = PageData.GetTotalCount(type);
        int start = 0;
        if (total > showCount)
        {
            Random rand = new Random(DateTime.Now.Second + 593);
            start = rand.Next(total - showCount);
        }
        start++;//随机数从0开始，页面从1开始。所以要加 1
        string pageCondition;
        if (type == 50)//总的分页根据id分
        {
            pageCondition = " id>=" + start.ToString() + " and id<" + (start + showCount).ToString();
        }
        else//指定类型的分页
        {
            pageCondition = PageData.GetPageStartEndCondition(type, start, showCount);
        }
        
        string sql = "select id, title from PublishJoke where " + pageCondition;
        OleDbConnection conn = AccessHelper.GetConnection();
        OleDbCommand cmd = new OleDbCommand(sql, conn);
        OleDbDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            rptRecommend.DataSource = reader;
            rptRecommend.DataBind();
        }
        finally
        {
            AccessHelper.CloseDbResource(conn, reader);
        }
         * */
    }
}
